package patrol.mobile.com.mobilepatrol.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.bean.TrafficAllBean;

/**
 * Created by admin on 2018/10/5.
 */

public class SummaryOfChargesAdapter2 extends RecyclerView.Adapter<TrafficAllAdapter2.ViewHolder> {

    private Context mContext;
    private List<TrafficAllBean> list = new ArrayList<>();

    public SummaryOfChargesAdapter2(Context mContext) {
        this.mContext = mContext;
    }

    public void setData(List<TrafficAllBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public TrafficAllAdapter2.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_traffic_all, parent, false);
        return new TrafficAllAdapter2.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(TrafficAllAdapter2.ViewHolder holder, int position) {
        if (position == 0) {
            holder.tv1.setText("日期");
            holder.tv2.setText("通行费(元)");
            holder.tv3.setText("减免金额(元)");
            holder.tv4.setText("合计(元)");
            holder.tv1.setBackgroundColor(mContext.getResources().getColor(R.color.excelBlue));
            holder.tv2.setBackgroundColor(mContext.getResources().getColor(R.color.excelBlue));
            holder.tv3.setBackgroundColor(mContext.getResources().getColor(R.color.excelBlue));
            holder.tv4.setBackgroundColor(mContext.getResources().getColor(R.color.excelBlue));
        } else {
            holder.tv1.setText(list.get(position - 1).getUpDate());
            holder.tv2.setText(list.get(position - 1).getToll()+"");
            holder.tv3.setText(list.get(position - 1).getGreenDerateToll() + "");
            holder.tv4.setText(list.get(position - 1).getTotal());
        }

    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size() + 1;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tv1;
        TextView tv2;
        TextView tv3;
        TextView tv4;

        public ViewHolder(View itemView) {
            super(itemView);
            tv1 = itemView.findViewById(R.id.itemFormText01);
            tv2 = itemView.findViewById(R.id.itemFormText02);
            tv3 = itemView.findViewById(R.id.itemFormText03);
            tv4 = itemView.findViewById(R.id.itemFormText04);
        }
    }

    public interface OnItemClickListener {
        void onItemClick(int parentPosition, int childPosition);
    }

    private TrafficAllAdapter2.OnItemClickListener mItemClickListener;

    public void setItemClickListener(TrafficAllAdapter2.OnItemClickListener itemClickListener) {
        mItemClickListener = itemClickListener;
    }
}
